package com.example.easybuy.controller;

import com.alibaba.fastjson.JSON;
import com.example.easybuy.pojo.EasybuyProduct;
import com.example.easybuy.pojo.EasybuyProductCategory;
import com.example.easybuy.service.EasybuyProductCategoryService;
import com.example.easybuy.service.EasybuyProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/easybuyProductCategory")
public class EasybuyProductCategoryController {

    @Autowired
    private EasybuyProductCategoryService easybuyProductCategoryService;

    @Autowired
    private EasybuyProductService easybuyProductService;

    @RequestMapping("/getAllProductCategory")
    public Object getAllProductCategory() {
        Map<String, Object> map = new HashMap<>();
        //获取产品分类
        List<EasybuyProductCategory> productCategoryList = easybuyProductCategoryService.allProductCategory();
        map.put("productCategoryList", productCategoryList);
        //获取各个楼层的商品
        List<List<EasybuyProduct>> floorProductList = new ArrayList<>();
        for (int i = 0; i < productCategoryList.size(); i++) {
            //查询1级分类下的2级商品
            List<EasybuyProduct> productList1 = easybuyProductService.getProductByParentId(productCategoryList.get(i).getId());
            floorProductList.add(productList1);
        }
        System.out.println("------------------------" + productCategoryList.get(0).getId());
        map.put("floorProductList", floorProductList);
        return map;
    }
}
